/* Creado el  18/04/2006 */
package com.angel.arquitectura.model.common;

import com.angel.arquitectura.model.objectId.ObjectId;
import com.angel.arquitectura.model.objectId.ObjectIdUtils;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;

/**
 *  Esta deberia ser la clase base para todos los objetos de negocio que no requieran ser persistidos
 * 
 * @author ALeinvand
 * @version $Revision: 1.5.4.10 $
 */
@MappedSuperclass
public abstract class BusinessObject implements Serializable{
    
    private static final long serialVersionUID = 1L;   
    
    @Id
    @Column(name="ID",length=36)    
    @Type(type="com.angel.arquitectura.dao.common.converter.ObjectIdConverter")
    private ObjectId objectId = ObjectIdUtils.createObjectId();


    protected BusinessObject() {
        super(); 
    }

    public int compareTo(Object otherObject) {
        BusinessObject otherBusinessObject = ( BusinessObject ) otherObject;

        return this.getId().compareTo(otherBusinessObject.getId());
    }


    public boolean equals(Object o) {
        if ( this == o ) {
            return true;
        }
        if ( !(o instanceof BusinessObject) ) {
            return false;
        }

        final BusinessObject businessObject = ( BusinessObject ) o;

        if ( this.getId() != null ? !this.getId().equals(businessObject.getId()) : businessObject.getId() != null ) {
            return false;
        }

        return true;
    }


    public int hashCode() {
        return (this.getId() != null ? this.getId().hashCode() : 0);
    }


    public String toString2() {
        final StringBuffer buf = new StringBuffer();
        buf.append("BusinessObject");
        buf.append("{id=").append(objectId);
        buf.append('}');
        return buf.toString();
    }

//////////////////////////////////////////////////////////////////////////////////////
////  GETTERS AND SETTERS  ///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
    
    public ObjectId getId() {
        return objectId;
    }
    public void setId(ObjectId objectId) {
        this.objectId = objectId;
    }

    /**
     * Devuelve el ObjectId representado como String.
     * util para no tener que andar agregando esta logica por todos lados.
     * @return String con la representacion del ObjectId
     * @author IFritzler
     * @version 1.0 
     */
    public String getIdAsString(){
    	return this.getId().getAsString();
    }
    
}
